package org.ucas.faker.web.fetcher.meta;

import org.ucas.faker.web.fetcher.meta.ColumnField;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;

public class ConstantField<T> extends ColumnField implements Serializable {

  public T value;

  public ConstantField(T t) {
    this.value = t;
  }
//
//  private Class<T> genericClazz(){
//    ParameterizedType superclass = (ParameterizedType) this.getClass().getGenericSuperclass();
//    return  (Class<T>) superclass.getActualTypeArguments()[0];
//  }

  @Override
  public String sql() {
    if(value == null) return "NULL";
//    Class<T> clazz = genericClazz();
    String res = value.toString();
    if(value instanceof String) return "\'"+res +"\'";
    return res;
  }
}
